package com.jilefojing.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import tk.mybatis.mapper.entity.Example;

import com.jilefojing.beans.pojos.Dictionary;
import com.jilefojing.dao.IDictionaryDao;
import com.jilefojing.dao.base.impl.BaseDao;
import com.jilefojing.dao.mapper.IDictionaryMapper;
import com.jilefojing.util.Detect;

/**
 * 
 * @author jgshun
 * 
 */
@Repository
public class DictionaryDao extends BaseDao<Dictionary> implements IDictionaryDao {
	@Autowired
	private IDictionaryMapper dictionaryMapper;

	@Override
	public List<Dictionary> getListByNodeName(String nodeName) {
		return dictionaryMapper.getListByNodeName(nodeName);
	}

	@Override
	public List<Dictionary> getListByNodeNamePefix(String nodeNamePefix) {
		return dictionaryMapper.getListByNodeNamePefix(nodeNamePefix);
	}

	@Override
	public List<Dictionary> getListByIds(List<Long> ids) {
		return dictionaryMapper.getListByIds(ids);
	}

	@Override
	public List<Dictionary> getListByParentId(Long parentId) {
		List<Long> parentIds = new ArrayList<Long>();
		parentIds.add(parentId);
		return this.getListByParentIds(parentIds);
	}

	@Override
	public List<Dictionary> getListByParentIds(List<Long> parentIds) {
		Example example = new Example(Dictionary.class);
		example.createCriteria().andIn(Dictionary.FIELD_PARENTID, parentIds);
		return super.getListByExample(example);
	}

	@Override
	public List<Dictionary> getListByParentIdAndNodeValues(Long parentId, List<String> nodeValues) {
		List<Long> parentIds = new ArrayList<Long>();
		parentIds.add(parentId);
		return this.getListByParentIdsAndNodeValues(parentIds, nodeValues);
	}

	@Override
	public List<Dictionary> getListByParentIdsAndNodeValues(List<Long> parentIds, List<String> nodeValues) {
		Example example = new Example(Dictionary.class);
		example.createCriteria().andIn(Dictionary.FIELD_PARENTID, parentIds).andIn(Dictionary.FIELD_NODE, nodeValues);
		return super.getListByExample(example);
	}

	@Override
	public boolean IsLeafNode(long id) {
		List<Dictionary> listByParentId = this.getListByParentId(id);
		if (!Detect.notEmpty(listByParentId)) {
			return true;
		}
		return false;
	}

}
